package com.hbzjjzx.zuul.zuul;


import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: liandyao
 * Date: 2020-01-08
 * Time: 14:24
 * Description: No Description
 */
@Component
public class UserLoginFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {

        RequestContext context = RequestContext.getCurrentContext();
        HttpServletRequest request = context.getRequest();

        String appId = request.getParameter("appId");

        if(appId!=null && "1".equals(appId)){
            return null ;
        }else{
            context.setSendZuulResponse(false); //过滤掉该请求,不执行转发(路由)
            context.setResponseStatusCode(401); //设置响应码
            context.setResponseBody("qing lian xi yjj");
            return null ;
        }
    }
}
